package argo.hot100.search2mid;

public class Search {
    public int search(int[] nums, int target) {

        int left = 0, right = nums.length - 1, mid;
        while (left <= right) {
            mid = (left + right) / 2;

            if (nums[mid] == target) {
                return mid;
            }

            //从有序的序列里去做排除，会更加简单；若左侧有序查看元素是够在左侧，若右侧有序则查看元素是够不在右侧
            if (nums[left] <= nums[mid] && (nums[left] <= target && nums[mid] >= target) || nums[mid] <= nums[right] && (nums[mid] > target || nums[right] < target)) {
                right = mid - 1;

            } else {
                left = mid + 1;
            }
        }
        return -1;


    }

}
